/**
 * 统一响应格式 - 与后端RestVO完全匹配
 */
export interface ApiResponse<T = any> {
  code: number
  msg: string
  data: T
}

/**
 * 分页响应格式
 */
export interface PageResponse<T = any> {
  list: T[]
  total: number
  page: number
  size: number
}

/**
 * 用户相关数据类型
 */
export interface UserInfo {
  id: number
  username: string
  nickname: string
  role: string
  token?: string
  refreshToken?: string
}

/**
 * 登录请求参数
 */
export interface LoginRequest {
  username: string
  password: string
}

/**
 * 注册请求参数
 */
export interface RegisterRequest {
  username: string
  password: string
  email?: string
}

/**
 * 业务异常类
 */
export class BusinessError extends Error {
  constructor(
    public code: number,
    public msg: string,
    public data?: any
  ) {
    super(msg)
    this.name = 'BusinessError'
  }
}

/**
 * 网络异常类
 */
export class NetworkError extends Error {
  constructor(
    public status: number,
    public statusText: string,
    public response?: any
  ) {
    super(`网络错误: ${status} ${statusText}`)
    this.name = 'NetworkError'
  }
}

/**
 * 认证异常类
 */
export class AuthError extends Error {
  constructor(public msg: string) {
    super(msg)
    this.name = 'AuthError'
  }
}